﻿using FunArts.EasyDevOps.Shared.Models.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FunArts.EasyDevOps.Shared.Models.SshClient.Command
{
    /// <summary>
    /// Nginx命令
    /// </summary>
    public class NginxCommand : ILinuxCommand
    {
        public NginxCommandTypeEnum CommandType { get; set; }

        public string BuildCommand(SystemVersionTypeEnum systemVersionType)
        {
            switch (CommandType)
            {
                case NginxCommandTypeEnum.Start:
                    var common= "sudo systemctl start nginx";
                    if (systemVersionType == SystemVersionTypeEnum.CentOS)
                    {
                        common = $"{common} && sudo setsebool -P httpd_can_network_connect 1";
                    }
                    return common;
                case NginxCommandTypeEnum.Stop:
                    return "sudo systemctl stop nginx";
                case NginxCommandTypeEnum.Restart:
                    return "sudo systemctl restart nginx";
                case NginxCommandTypeEnum.Reload:
                    return "sudo systemctl reload nginx";
                case NginxCommandTypeEnum.Status:
                    return "sudo systemctl status nginx";
                case NginxCommandTypeEnum.Enable:
                    return "sudo systemctl enable nginx";
                case NginxCommandTypeEnum.Test:
                    return "sudo nginx -t";
                default:
                    break;
            }
            return string.Empty;
        }
    }
}
